cmake_minimum_required(VERSION 3.10)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(QT NAMES Qt6 COMPONENTS Core Widgets REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Network REQUIRED)
find_package(QT NAMES Qt6 COMPONENTS Charts)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Charts)
find_package(QT NAMES Qt6 COMPONENTS Graphs QuickWidgets Quick)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Graphs QuickWidgets Quick)
include_directories(${TASKBUS_INTERFACEDIR})

set(PRJ_RESOURCES
	dialogplots.qrc
)

# 确认有没有 charts 或者 graphs 库，没有的话，就不显示折线图了。
if (Qt${QT_VERSION_MAJOR}Charts_FOUND)
	message("Charts found.")
	set(PRJ_HEADERS
		charts/dialogplots.h
		listen_thread.h
		spectrowidget.h
	)
	set(PRJ_SOURCES
		charts/dialogplots.cpp
		listen_thread.cpp
		main.cpp
		spectrowidget.cpp
	)
	set(PRJ_FORMS
		charts/dialogplots.ui
	)
	set(PLOTS_PLUGIN_LIB
		Qt${QT_VERSION_MAJOR}::Charts
	)
	include_directories(charts)
elseif (Qt${QT_VERSION_MAJOR}Graphs_FOUND)
	message("Graphs found.")
	set(PRJ_HEADERS
		graphs/dialogplots.h
		listen_thread.h
		spectrowidget.h
	)
	set(PRJ_SOURCES
		graphs/dialogplots.cpp
		listen_thread.cpp
		main.cpp
		spectrowidget.cpp

	)
	set(PRJ_FORMS
		graphs/dialogplots.ui
	)
	set(PLOTS_PLUGIN_LIB
		Qt${QT_VERSION_MAJOR}::Graphs Qt${QT_VERSION_MAJOR}::QuickWidgets Qt${QT_VERSION_MAJOR}::Quick
	)
	include_directories(graphs)
else()
	message("Error, QtCharts or QtGraphs needed.")
endif()


# ========================GUI Exe========================
qt_add_executable(sink_plots
	MANUAL_FINALIZATION
	${PRJ_HEADERS}
	${PRJ_SOURCES}
	${PRJ_FORMS}
	${PRJ_RESOURCES}
)

target_link_libraries(sink_plots PRIVATE
	Qt${QT_VERSION_MAJOR}::Widgets
	Qt${QT_VERSION_MAJOR}::Network
	${PLOTS_PLUGIN_LIB}
	${TBLinkExtra}
)

set_target_properties(sink_plots PROPERTIES
	MACOSX_BUNDLE_GUI_IDENTIFIER taskBus.modules.sink_plots
	MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
	MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
	MACOSX_BUNDLE TRUE
	WIN32_EXECUTABLE TRUE
)

# ====copy doc
add_custom_command(TARGET sink_plots
	POST_BUILD
	COMMAND echo Copy Handbook to EXE path
	COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sink_plots.md ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sink_plots.md
)

qt_finalize_executable(sink_plots)

